package com.example.test.controller;

import com.example.test.model.Course;
import com.example.test.service.CourseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("course")
public class CourseController extends BaseController {
    private CourseService courseService;

    public CourseController(CourseService courseService) {
        this.courseService = courseService;
    }

    @PostMapping("create")
    private String create(Course course ){
        courseService.create(course);
        return "redirect:/course/queryAll";
    }

    @GetMapping("queryAll")
    private String queryAll(Course  course){
        session.setAttribute("course",courseService.queryAll());
        return "redirect:/course/list.jsp";
    }
    @GetMapping("queryById/{id}")
    private String queryById(@PathVariable("id") int id){
        session.setAttribute("course",courseService.queryById(id));
        return "redirect:/course/edit.jsp";
    }
    @PostMapping("modify")
    private String modify(Course course){
        courseService.modify(course);
        return "redirect:/course/queryAll";
    }
    @GetMapping("removeById/{id}")
    private String removeById(@PathVariable("id") int id){
            courseService.removeById(id);
            return "redirect:course/queryAll";
    }

}
